<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>校园论坛系统 - 登录</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/jquery-3.5.1/jquery-3.5.1.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- 自定义样式 -->
    <link href="css/login.css" rel="stylesheet">
    <style>
    </style>
    <script>
        $(document).ready(function() {
            checkRememberMe();
            function checkRememberMe() {
               /* var rememberMeToken = getCookie("rememberMeToken");
                console.log("rememberMeToken:" + rememberMeToken)
                if (rememberMeToken !== "") {
                    $.ajax({
                        url: "autoLogin?rememberMeToken=" + rememberMeToken,
                        type: "get",
                        success: function(response) {
                            if (response.data === 0) {
                                window.location.href = "userIndex.jsp";
                            } else if (response.data === 1) {
                                window.location.href = "adminIndex.jsp";
                            } else {
                                console.log("Unknown role");
                            }
                        },
                        error: function() {
                            console.log("自动登录失败");
                        }
                    });
                }*/
            }

            function getCookie(name) {
                var cookieName = name + "=";
                var decodedCookie = decodeURIComponent(document.cookie);
                var cookieArray = decodedCookie.split(';');
                for (var i = 0; i < cookieArray.length; i++) {
                    var cookie = cookieArray[i];
                    while (cookie.charAt(0) === ' ') {
                        cookie = cookie.substring(1);
                    }
                    if (cookie.indexOf(cookieName) === 0) {
                        return cookie.substring(cookieName.length, cookie.length);
                    }
                }
                return "";
            }

            $('#LoginFree').change(function() {
                if (this.checked) {
                    $('#isLoginFree').val('true');
                }
            });


        });
    </script>
</head>
<body>

<div class="container">
    <form class="form-signin" method="post" action="login">
        <h3 class="form-signin-heading text-center">登录</h3>
        <div class="form-group">
            <label for="inputUsername" class="sr-only">用户名</label>
            <input type="text" id="inputUsername" name="username" class="form-control" placeholder="用户名" required autofocus>
        </div>
        <div class="form-group">
            <label for="inputPassword" class="sr-only">密码</label>
            <input type="password" id="inputPassword" name="password" class="form-control" placeholder="密码" required>
        </div>
        <div class="form-group">
            <label for="selectRole" class="sr-only">权限</label>
            <select id="selectRole" name="role" class="form-control">
                <option value="0">学生</option>
                <option value="1">管理员</option>
            </select>
        </div>
        <div class="form-group">
            <label for="inputCaptcha" class="sr-only">验证码</label>
            <input type="text" id="inputCaptcha" name="captcha" class="form-control" placeholder="验证码" required>
            <img src="generateCaptcha.jsp" alt="Captcha Image" onclick="this.src='generateCaptcha.jsp?'+Math.random();" title="点击刷新验证码" style="cursor: pointer;">
        </div>
        <p class="text-danger">${errorMessage}</p> <!-- 显示错误信息 -->
        <button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
        <a class="btn btn-lg btn-register btn-block" href="register.jsp">注册</a>
       <%-- <div class="form-check mt-3">
            <input class="form-check-input" type="checkbox" id="LoginFree" name="isLoginFree">
            <label class="form-check-label" for="isLoginFree">
                30天免登录
            </label>
        </div>
        <input id="isLoginFree" name="isLoginFree" type="hidden">--%>
    </form>
</div>

</body>
</html>
